package com.boot.core.protocol

class OperateRequestOfApp {

    val jsonrpc: String = "2.0"
    var id: String? = null
    var method: String? = null
    var params: OperateParamsOfApp? = null
    var sign: String? = null

    fun OperateRequestOfApp(operateRequestOfApp: OperateRequestOfApp?): Any? {
        this.id = operateRequestOfApp?.id
        this.method = operateRequestOfApp?.method
        this.params = OperateParamsOfApp(operateRequestOfApp?.params)
        this.sign = operateRequestOfApp?.sign
        return this
    }

    class OperateParamsOfApp(operateParamsOfApp: OperateParamsOfApp?) {
        var code: String? = operateParamsOfApp?.code
        var msg: String? = operateParamsOfApp?.msg
        // 此处应看前端传入参数是否为json字符串
        var data: Data? = operateParamsOfApp?.data

        class Data(data: OperateParamsOfApp.Data?) {
            var version: String? = data?.version
            var appId: String? = data?.appId
            var sessionId: String? = data?.sessionId
            var userInfo: UserInfo? = data?.userInfo
            // 开启事务标记，1 为开启， 0 不开启。开启事务，所有的操作事务一致性。否则，操作互不影响。若同一 operations 中有 多条 数据， 这些 数据默认 具有/事务一致性。 对 不同的 operations 的 事务一致性，由transaction开启
            var transaction: Int? = data?.transaction
            var operations: ArrayList<Operation>? = data?.operations

            class UserInfo(userInfo: UserInfo?) {
                var userId: String? = userInfo?.userId
                var userName: String? = userInfo?.userName
                var userDeptNo: String? = userInfo?.userDeptNo
                var sn: String? = userInfo?.sn
                var sfzh: String? = userInfo?.sfzh
                var extAttr: HashMap<String, Any?>? = userInfo?.extAttr
            }

            class Operation(operation: Operation?) {
                // 操作类型，1 新增， 2 修改， 3 删除
                var operationType: Int? = operation?.operationType
                var operationId: String? = operation?.operationId
                var sourceId: String? = operation?.sourceId
                var dataObjId: String? = operation?.dataObjId
                var condition: String? = operation?.condition
                var data: ArrayList<Data>? = operation?.data

                class Data(fieldValues: ArrayList<HashMap<String, Any?>>?) {
                    var fieldValues: ArrayList<HashMap<String, Any?>>? = fieldValues
                }
            }
        }
    }

}